package com.ruoyi.web.controller.ufox;

import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.ufox.domain.BisDevicePhoto;
import com.ruoyi.ufox.service.IBisDevicePhotoService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.page.TableDataInfo;

import java.util.List;

/**
 * 照片管理Controller
 * 
 * @author ufoxs
 * @date 2022-08-16
 */
@RestController
@RequestMapping("/bussiness/photo")
public class BisDevicePhotoController extends BaseController
{
    @Autowired
    private IBisDevicePhotoService bisDevicePhotoService;

    /**
     * 查询照片管理列表
     */
    @PreAuthorize("@ss.hasPermi('bussiness:photo:list')")
    @GetMapping("/list")
    public TableDataInfo list(BisDevicePhoto bisDevicePhoto)
    {
        startPage();
        List<BisDevicePhoto> list = bisDevicePhotoService.selectBisDevicePhotoList(bisDevicePhoto);
        return getDataTable(list);
    }

    /**
     * 导出照片管理列表
     */
    @PreAuthorize("@ss.hasPermi('bussiness:photo:export')")
    @Log(title = "照片管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BisDevicePhoto bisDevicePhoto)
    {
        List<BisDevicePhoto> list = bisDevicePhotoService.selectBisDevicePhotoList(bisDevicePhoto);
        ExcelUtil<BisDevicePhoto> util = new ExcelUtil<BisDevicePhoto>(BisDevicePhoto.class);
        util.exportExcel(response, list, "照片管理数据");
    }

    /**
     * 获取照片管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('bussiness:photo:query')")
    @GetMapping(value = "/{photoId}")
    public AjaxResult getInfo(@PathVariable("photoId") Long photoId)
    {
        return AjaxResult.success(bisDevicePhotoService.selectBisDevicePhotoByPhotoId(photoId));
    }

    /**
     * 新增照片管理
     */
    @PreAuthorize("@ss.hasPermi('bussiness:photo:add')")
    @Log(title = "照片管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BisDevicePhoto bisDevicePhoto)
    {
        if (this.bisDevicePhotoService.select(bisDevicePhoto.getModelName(),bisDevicePhoto.getColorName(),null)==true) {
            return AjaxResult.error(500,"设备编号已经存在");
        }
        return toAjax(bisDevicePhotoService.insertBisDevicePhoto(bisDevicePhoto));
    }

    /**
     * 修改照片管理
     */
    @PreAuthorize("@ss.hasPermi('bussiness:photo:edit')")
    @Log(title = "照片管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BisDevicePhoto bisDevicePhoto)
    {
        if (this.bisDevicePhotoService.select(bisDevicePhoto.getModelName(),bisDevicePhoto.getColorName(), bisDevicePhoto.getPhotoId())==true) {
            return AjaxResult.error(500,"设备编号已经存在");
        }
        return toAjax(bisDevicePhotoService.updateBisDevicePhoto(bisDevicePhoto));
    }

    /**
     * 删除照片管理
     */
    @PreAuthorize("@ss.hasPermi('bussiness:photo:remove')")
    @Log(title = "照片管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{photoIds}")
    public AjaxResult remove(@PathVariable Long[] photoIds)
    {
        return toAjax(bisDevicePhotoService.deleteBisDevicePhotoByPhotoIds(photoIds));
    }
}
